//
//  TLTabBarController.m
//  Papa
//
//  Created by wf on 16/7/16.
//  Copyright © 2016年 tongli. All rights reserved.
//

#import "TLTabBarController.h"
#import "TLTabBar.h"

#import "TLNavgationController.h"
#import "TLMeViewController.h"
#import "TLMessageViewController.h"
#import "TLTaskViewController.h"
#import "TLHomeViewController.h"


@interface TLTabBarController ()<TLTabBarDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (nonatomic, weak) UIImageView *imageView;


@end

@implementation TLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //初始化自定义tabBar
    TLTabBar *tabBar = [[TLTabBar alloc] init];
    tabBar.delegate = self;
    [tabBar setBackgroundImage:[UIImage imageNamed:@"背景_02"]];
    
    //kvc赋值
    [self setValue:tabBar forKeyPath:@"tabBar"];
    
    //首页
    TLHomeViewController *homeCtrl = [TLHomeViewController new];
    [self addChildViewController:homeCtrl imageName:@"首页1" title:nil index:0];
    
    //任务
    TLTaskViewController *taskCtrl = [TLTaskViewController new];
    [self addChildViewController:taskCtrl imageName:@"任务1" title:nil index:1];
    
    //啪啪圈
    TLMessageViewController *messageCtrl = [TLMessageViewController new];
    [self addChildViewController:messageCtrl imageName:@"啪啪圈1" title:nil index:2];
    
    //我的
    TLMeViewController *proCtrl = [TLMeViewController new];
    [self addChildViewController:proCtrl imageName:@"熊的1" title:nil index:3];
    
    
}


//添加子控制器，设置标题与图片
- (void)addChildViewController:(UIViewController *)childCtrl imageName:(NSString *)imageName title:(NSString *)title index:(int)index {
    //设置图片
    childCtrl.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childCtrl.tabBarItem.tag = index;
    childCtrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_s",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    childCtrl.title = title;
    
    childCtrl.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    TLNavgationController *navCtrl = [[TLNavgationController alloc] initWithRootViewController:childCtrl];
    [self addChildViewController:navCtrl];
    
}

- (void)tabBar:(TLTabBar *)tabBar didSelectTakePhotoBtn:(UIButton *)btn {
    NSLog(@"开始拍照");
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    }
}

@end
